Write-Host "Testing WorkflowCore functionality..." -ForegroundColor Green

$baseUrl = "http://localhost:8080"

try {
    Write-Host "Testing login..." -ForegroundColor Cyan
    
    $loginData = @{
        username = "admin"
        password = "1q2w3E*"
    } | ConvertTo-Json
    
    $headers = @{
        "Content-Type" = "application/json"
    }
    
    $loginResponse = Invoke-RestMethod -Uri "$baseUrl/api/account/login" -Method POST -Body $loginData -Headers $headers
    
    if ($loginResponse.success) {
        Write-Host "Login successful!" -ForegroundColor Green
        
        $token = $loginResponse.accessToken
        $authHeaders = @{
            "Authorization" = "Bearer $token"
            "Content-Type" = "application/json"
        }
        
        Write-Host "Testing workflow instances..." -ForegroundColor Cyan
        try {
            $instancesResponse = Invoke-RestMethod -Uri "$baseUrl/api/app/workflow/instances" -Method GET -Headers $authHeaders
            Write-Host "Workflow instances retrieved successfully!" -ForegroundColor Green
        }
        catch {
            Write-Host "Failed to get workflow instances: $($_.Exception.Message)" -ForegroundColor Red
        }
        
        Write-Host "Testing pending approvals..." -ForegroundColor Cyan
        try {
            $pendingResponse = Invoke-RestMethod -Uri "$baseUrl/api/app/workflow/pending-approvals" -Method GET -Headers $authHeaders
            Write-Host "Pending approvals retrieved successfully!" -ForegroundColor Green
        }
        catch {
            Write-Host "Failed to get pending approvals: $($_.Exception.Message)" -ForegroundColor Red
        }
    }
    else {
        Write-Host "Login failed: $($loginResponse.message)" -ForegroundColor Red
    }
}
catch {
    Write-Host "Test exception: $($_.Exception.Message)" -ForegroundColor Red
}

Write-Host "Test completed!" -ForegroundColor Green 